package test17.homework;

public class Homework02 {
    public static void main(String[] args) {
        T t = new T();
        Thread thread = new Thread(t);
        Thread thread1 = new Thread(t);
        thread.start();
        thread1.start();
    }
}

class T implements Runnable {
    private static int money = 10000;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                if (money < 1000) {
                    System.out.println("余额不足");
                    break;
                }
                money = money - 1000;
                System.out.println(Thread.currentThread().getName() + " 取出了1000 当前余额=" + money);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}